import React, { useRef } from "react";

const withLogger = (Cmp) => {
  const CmpWithLogger = (props) => {
    const cmpRef = useRef(null);

    const onGetUserInfo = () => {
      const res = cmpRef.current.getUser();
      // console.log(res);
      if (props.submit) {
        props.submit(res);
      }
    }

    return (
      <div style={{ width: '300px' }}>
        <Cmp ref={cmpRef} {...props} />
        <hr />
        <button onClick={onGetUserInfo}>获取用户信息</button>
      </div>
    )
  }

  return CmpWithLogger;
}

export default withLogger;
